package com.hellpro.lolbox.home.collections;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.hellpro.lolbox.config.UrlConfigs;
import com.hellpro.lolbox.db.CollectDao;
import com.hellpro.lolbox.utils.OkHttpClientUtils;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;

/**
 * Package_Name: com.hellpro.lolbox.home.collections
 * Description :
 * author: HellPermanent
 * date:  2016/10/23 19:07
 * remarks：
 */
public class CollectInformationDowm {
    private Context mContext;
    public CollectInformationDowm(Context context){
        mContext = context;

    }
    //调用它进行收藏。。
    public  void downData(final String name, final String qu){
        new Thread(
                new Runnable() {
                    @Override
                    public void run() {
                        CollectDao collectDao = new CollectDao(mContext);
                        SQLiteDatabase db = collectDao.getDb();
                        ContentValues contentValues = new ContentValues();
                                contentValues.put("name",name);
                        contentValues.put("qu",qu);

                        //这里讲jsonobject放入到数据库中。。好聪明啊
                        String path = UrlConfigs.ZHANJICHOUCANG + qu + "&target="  + name;

                        try {
                            String json = OkHttpClientUtils.getStringFromURL(mContext, path, null);
                            if (json!=null) {
                                JSONObject jsonObject = new JSONObject(json);

                                String jsons  = jsonObject.toString();


                                contentValues.put("jsonobject",jsons);

                                long colloct_infro = db.insert("colloct_infro", null, contentValues);


                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }
                }
        ).start();
    }
}
